package student;

import SQL.Configuration;

import java.sql.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author: 保护小周
 * Date: 2022-11-15
 * Time: 8:37
 */
public class User implements Configuration {

    public static boolean register(String uname, String pad) throws SQLException {
        try {
            Class.forName(dirver);
           // System.out.println("驱动加载成功");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.out.println("驱动加载失败！");
        }

        Connection connection = DriverManager.getConnection(
                url, username, password);
       // System.out.println("数据库连接成功");

        //创建执行环境
        Statement statement = connection.createStatement();

        String sql = "SELECT user_name,password FROM user WHERE " + username + " = username";

        // 执行SQL 语句 得到结果集
        ResultSet resultSet = statement.executeQuery(sql); //sql 查询语句
        if (resultSet.next() == false) {
            System.out.println("用户不存在,或用户名输入错误");
            return false;
        } else {
            String uname1 = resultSet.getString("user_name");
            String password1  = resultSet.getString("password");

            if(pad.equals(password1)) {
                return true;
            } else {
                System.out.println("密码错误！");
            }
        }

        return false;
    }
}
